package com.rohan.apps.mileagetracker.server.db.service;

import java.util.HashSet;

import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.rohan.apps.mileagetracker.server.db.models.AppUser;

public class AppUserDao extends ObjectifyDao<AppUser> {
	public AppUser getUser(){
		return this.getUser();
	}
	public void saveUserInfo(AppUser user){
		this.put(user);
	}
	public AppUser LogIn(String appUrl){
		UserService userService=  UserServiceFactory.getUserService();
		AppUser user=null;
		if(userService.isUserLoggedIn()){
			//logged in
			user = new AppUser(userService.getCurrentUser().getEmail());
			user.setLoggedIn(true);
			user.setLogoutUrl(userService.createLogoutURL(appUrl));
		}
		else{
			//not logged in
			user= new AppUser();
			user.setLoggedIn(false);
			//user.setLoginUrl(userService.createLoginURL(appUrl));
			user.setLoginUrl(userService.createLoginURL(appUrl,null,"google.com/accounts/o8/id",new HashSet<String>()));
			
		}
		return user;
	}
}
